package com.config.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.stereotype.Repository;

import com.base.dao.TemplateDaoImpl;
import com.config.entity.EquMold;

@Repository(value="equMoldDao")
public class EquMoldDaoImpl extends TemplateDaoImpl<EquMold,Integer> implements EquMoldDao{

	@Override
	public List<EquMold> findByAll(int start, int limit) {
		StringBuilder sb = new StringBuilder("select top "+limit+" * from (")
			.append("select row_number() over(order by id desc ) rowindex,* from ")
			.append(" equMold where 1=1");
		Map<String, Object> params=new HashMap<String, Object>();
		sb.append(") u where u.rowindex>:start");
		params.put("start", (start-1)*limit);
		params.put("limit", limit);
		return jt.query(sb.toString(), params,
				ParameterizedBeanPropertyRowMapper.newInstance(EquMold.class));
	}

	@Override
	public int countByAll() {
		StringBuffer sb = new StringBuffer("select count(*) from equMold");
		Map<String, Object> params=new HashMap<String, Object>();
		return jt.queryForObject(sb.toString(), params, Integer.class);
	}

}
